<div class="comments index form">
<h2><?php __('Comments');?></h2>
<p class="searcher">
    <?php e($form->input('Comment.search',
        array('class'=>'input text', 'label'=>false))); ?>
    <?php e($html->link(__('Search Comments', true),
        array('controller'=>'comments', 'action'=>'index'),
        array('class'=>'button submit', 'style'=>'clear:none', 'id'=>'link_search'))); ?>
</p>
<!-- Table Navigation -->
<div class="tablenav">
    <div class="batchactions"></div>
    <?php echo $this->element('pager'); ?>
</div>
<!-- Table Content Area -->
<table id="table_comments" class="table fixed">
    <thead title="<?php __('Click a column to sort data table'); ?>">
        <tr>
            <th width="5%" class="checkbox" title="<?php __('Click to select/deselect all records'); ?>"><input type="checkbox" class="checkbox" /></th>
            <th width="20%"><?php __('Submitter');?></th>
            <th width="45%"><?php echo $paginator->sort('content');?></th>
            <th width="30%"><?php echo $paginator->sort('post_id');?></th>
        </tr>
    </thead>
    <tfoot title="<?php __('Click a column to sort data table'); ?>">
        <tr>
            <th class="checkbox" title="<?php __('Click to select/deselect all records'); ?>"><input type="checkbox" class="checkbox" /></th>
            <th><?php __('Submitter');?></th>
            <th><?php echo $paginator->sort('content');?></th>
            <th><?php echo $paginator->sort('post_id');?></th>
        </tr>
    </tfoot>
    <tbody>
        <?php foreach ($comments as $i=>$comment):
            $class = $i++ % 2 == 0 ? ' class="altrow"' : ''; ?>
        <tr<?php echo $class;?>>
            <td class="checkbox"><input type="checkbox" class="checkbox" /></td>
            <td class="author">
                <?php //echo $html->link($comment['User']['username'], array('controller' => 'users', 'action' => 'view', $comment['User']['id'])); ?>
                <?php $name = empty($comment['User']['nickname']) ? $comment['User']['username'] : $comment['User']['nickname'] ;?>
                <strong><?php e($name); ?></strong><br />
                <p class="email">
                    <?php echo $text->autoLinkEmails($comment['User']['email'],
                        array('title'=>sprintf(__('Send mail to: %s', true), $comment['User']['username']))); ?>
                </p>
                <p class="client">
                    <?php echo $html->link($comment['Comment']['client'],
                        array('client' => $comment['Comment']['client']),
                        array('title' => __('View comments posted at this client', true))); ?>
                </p>
            </td>
            <td class="comment">
                <p class="created">
                    <?php __('Submitted on'); ?>&nbsp;
                    <?php echo $html->link($time->format($options['longDateFormat'], $comment['Comment']['created']),
                        array('created' => $time->format($options['queryDateFormat'], $comment['Comment']['created'])),
                        array('title' => sprintf(__('View comments submitted around %s', true), $time->format($options['queryDateFormat'], $comment['Comment']['created'])))); ?>
                </p>
                <p class="content"><?php echo $comment['Comment']['content']; ?></p>
                <!-- Comment actions -->
                <?php if($comment['Comment']['approved']){
                        $app_display = 'none';
                        $unapp_display = 'inline';
                    }else{
                        $app_display = 'inline';
                        $unapp_display = 'none';
                    }
                ?>
                <p class="actions">
                    <span class="approve" style="display: <?php e($app_display); ?>">
                        <?php echo $html->link(__('Approve', true),
                            array('action'=>'switchOn', 'approved', $comment['Comment']['id']),
                            array('title' => __('approve the comment so that others will see it', true))); ?>
                    </span>
                    <span class="unapprove" style="display: <?php e($unapp_display); ?>">
                        <?php echo $html->link(__('Unpprove', true),
                            array('action'=>'switchOff', 'approved', $comment['Comment']['id']),
                            array('title' => __('unapprove offensive comments', true))); ?>
                    </span>
                    <span class="delete"><?php echo $html->link(__('Delete', true), array('action'=>'delete', $comment['Comment']['id'])); ?></span>
                </p>
            </td>
            <td class="post">
                <!-- Post.Comment -->
                <a href="javascript:void(0)"
                    title="<?php printf(__('%d comments in total', true), $comment['Post']['comment_count'])?>"
                    class="has_comment">
                    <span><?php e($comment['Post']['comment_count']); ?></span>
                </a>
                <!-- Post.Title -->
                <?php echo $html->link($comment['Post']['title'],
                    array('post_id' => $comment['Post']['id']),
                    array('title' => __('View comments on this post', true))
                ); ?>
                <!-- External view link -->
                <?php e($html->link('' ,
                    array('controller' => 'posts', 'action'=>'view', $comment['Post']['id']),
                    array(
                        'title'=>__('Click to view the post in another page', true),
                        'class'=>'external')
                )); ?>
            </td>
        </tr>
        <?php endforeach; ?>
    </tbody>
</table>
</div>

<?php //debug($comments); ?>
<script type="text/javascript">
jQuery(function(){
    $('tbody tr').hover($.sme.cbk.showActions, $.sme.cbk.hideActions);
    /* Bind Group Edit/View/Delete callbacks */
    $('table#table_comments p.actions a[href*=switchOn]')
        .click($.sme.cbk.ajaxSwitchOn);
    $('table#table_comments p.actions a[href*=switchOff]')
        .click($.sme.cbk.ajaxSwitchOff);
    $('table#table_comments p.actions a[href*=delete]')
        .click($.sme.cbk.ajaxDelete);
    /* Observe search button click */
    $('a#link_search').click(function(){
        var value = $('#CommentSearch').fieldValue()[0];
        if(value != ''){
            this.href = this.href + '/index/content:' + value;
        }else{
            return false;
        }
    });
});
</script>